﻿using Fast.ConfigureOptions;
using Microsoft.Extensions.Configuration;
using System.Text.Encodings.Web;
using System.Text.Json;

namespace Fast
{
    [SkipScan]
    public class FastSystemTextJsonSerializerOptions : IConfigureOptions<FastSystemTextJsonSerializerOptions>
    {
        public JsonSerializerOptions JsonSerializerOptions { get; private set; }

        public void PostConfigure(FastSystemTextJsonSerializerOptions options, IConfiguration configuration)
        {
            options.JsonSerializerOptions ??= new JsonSerializerOptions(JsonSerializerDefaults.Web)
            {
                //阅读注释处理，怎么处理Json字符串中的注释
                ReadCommentHandling = JsonCommentHandling.Skip,
                //允许尾部的逗号
                AllowTrailingCommas = true,
                
                Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
        }
    }
}
